package com.tarena.lbs.basic.web.service.impl;

import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.repository.StoreChainRepository;
import com.tarena.lbs.basic.web.service.IStoreChainService;
import com.tarena.lbs.pojo.basic.dos.StoreChainQueryDO;
import com.tarena.lbs.pojo.basic.query.StoreChainQuery;
import com.tarena.lbs.pojo.basic.vo.StoreChainVO;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StoreChainServiceImpl implements IStoreChainService {

    @Autowired
    private StoreChainRepository storeChainRepository;

    @Override
    public PageResult<StoreChainVO> getAll(StoreChainQuery query) {
        int page = query.getPageNo();
        int pageSize = query.getPageSize();
        //new PageQuery(page, pageSize);
        List<StoreChainQueryDO> boList = storeChainRepository.selectList(query);
        PageInfo<StoreChainQueryDO> pageInfo = new PageInfo<>(boList);
        List<StoreChainVO> storeChainVOList = pageInfo.getList().stream().map(storeChainDO -> {
            StoreChainVO storeChainVO = new StoreChainVO();
            if (storeChainDO!=null){
                BeanUtils.copyProperties(storeChainDO, storeChainVO);
            }
            return storeChainVO;
        }).collect(Collectors.toList());
        PageResult<StoreChainVO> pageResult = new PageResult<>();
        pageResult.setObjects(storeChainVOList);
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPageNo(query.getPageNo());
        pageResult.setPageSize(pageSize);
        return pageResult;

    }

    @Override
    public void enableStatusById(Integer id) {
        int row = storeChainRepository.enableStatusById(id);
    }

    @Override
    public void disableStatusById(Integer id) {
        int row = storeChainRepository.disableStatusById(id);
    }
}
